import requests
import os


def upload_file(path):
    file_name = os.path.basename(path)

    url = "https://qianfan.baidubce.com/v2/app/conversation/file/upload"

    payload = {
        'app_id': '79f5f6e2-0e16-4e98-ba14-e2ef6341d343',
        'conversation_id': '5c8cd1f5-1438-4241-a0cc-0ac9067e24a7'
    }
    files = [
        ('file', (file_name, open(path, 'rb'), 'image/jpeg'))
    ]
    headers = {
        'X-Appbuilder-Authorization': 'Bearer bce-v3/ALTAK-Espg8KHYJBAQ94MfVHMQ4/3fe5583d4006d1519c96b8f817d49b27042003a6'
    }

    response = requests.request("POST", url, headers=headers, data=payload, files=files)

    # print(response.text)
    return response.json()["id"]

# if __name__ == '__main__':
#     upload_file("./a.jpg")
